<?php

declare(strict_types=1);

namespace app\user\controller;

use think\facade\Db;
use think\facade\Session;
use think\facade\View;

class Index
{
    public function index()
    {
         
        return view();
    }

    public function login()
    {
        //获取用户提交的表单数据 
        if(request()->isPost()){
            $username = input('username');
            $password = input('password');
            
            // 查询用户信息  
            $user = Db::table('user')->where('username', $username)->find();  
            if (!$user) {  
                return '用户不存在'; // 如果用户不存在，返回错误信息  
            }  

            if($password != $user['password']){
                return '密码不正确';
            } 
            session::set('Id', $user['Id']);  
            session::set('username', $user['username']); 

            dump(session::get('username'));

            dump(session('Id'));
            View::assign('user', $user);

            return View::fetch('index');
        }
        else{
        
            return View();
        }     }
        



    public function register()
    {
        return view();
    }

    public function logout()
    {
        return view();
    }
}
